<?php

/**
 * 工厂模式
 */

interface Animal
{
    public function run();
    public function say();
}
class Cat implements Animal
{
    public function run()
    {
        echo "cat run";
    }
    
    public function say()
    {
        echo "cat say";
    }
}
class Dog implements Animal
{
    public function run()
    {
        echo "dog run";
    }
    
    public function say()
    {
        echo "dog say";
    }
}


abstract class Factory
{
    abstract static function  createAnimal();
}
class CatFactory extends Factory
{
    public static function createAnimal()
    {
        return new Cat();
    }
}
class DogFactory extends Factory
{
    public static function createAnimal()
    {
        return new Dog();
    }
}

$cat = CatFactory::createAnimal();
$cat->say();
$cat->run();

$dog = DogFactory::createAnimal();
$dog->say();
$dog->run();
